<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ajaxupload
 *
 * @author Chris Sim
 */

  Yii::import('zii.widgets.jui.CJuiInputWidget');


class ajaxupload extends CJuiInputWidget {
    //put your code here
    public $id='ajaxupload';
    
    public function run() {
        $this->publishAssets();
        $htmlOptions = $this->htmlOptions;
        $htmlOptions['type'] = 'file';
        $htmlOptions['multiple'] = 'multiple';
        $htmlOptions['id'] = $this->getId();
        echo CHtml::tag('input',$htmlOptions);
    }
    private function publishAssets() {
        $id = $this->getId();
        $filedir = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.widgets.AjaxUpload.script'));
        $cs = Yii::app()->getClientScript();

        // Publish core script
        $cs->registerCoreScript('jquery');
        $cs->registerScriptFile($filedir.'/jquery.upload.js');

        //make script
        $options = '';
        if(!empty($this->options))
            $options=CJavaScript::encode($this->options);
        $js = "$('#{$id}').html5_upload({$options});";
        $cs->registerScript(__CLASS__.'#'.$this->id, $js, CClientScript::POS_READY);
    }
}
?>
